//
// Created by tang on 22-4-20.
//

#ifndef DIARYTOOL_TEMPLATE_MANAGER_HPP
#define DIARYTOOL_TEMPLATE_MANAGER_HPP

#include <string>
#include <list>

#include "json/json.hpp"

struct WorkItem;

struct TemplateData {
    std::string default_title;          // 默认标题
    double default_hour;                // 默认耗时
    std::vector<int32_t> default_tags;  // 默认标签ID集合
    int32_t default_issue;              // 默认问题ID
    int32_t default_activity;           // 默认活动ID

    NLOHMANN_DEFINE_TYPE_INTRUSIVE(TemplateData, default_title, default_hour, default_tags, default_issue,
        default_activity)
};

struct TemplateInfo {
    std::string template_name;
    TemplateData data;

    NLOHMANN_DEFINE_TYPE_INTRUSIVE(TemplateInfo, template_name, data)
};

class TemplateManager final {
    TemplateManager();
    ~TemplateManager();

    void LoadFromFile();
    void SaveToFile();
public:
    static TemplateManager& Instence();

    std::list<TemplateInfo> AllTemplates();

    const std::list<TemplateInfo>& AllTemplatesRef() const;

    void SetTemplates(std::list<TemplateInfo> templates);

    void ApplyWorkItem(WorkItem* item, int template_index) const;

    void ApplyChange();

    void Reload();

private:
    std::list<TemplateInfo> m_templates_;
};

#endif //DIARYTOOL_TEMPLATE_MANAGER_HPP
